using Reign.Core.MathI32;

namespace Reign.Video.XNA
{
	public class ViewPort : ViewPortI
	{
		#region Properties
		private Video video;
		#endregion

		#region Constructors
		public ViewPort(VideoI video)
		{
			this.video = (Video)video;
		}

		public ViewPort(VideoI video, int x, int y, int width, int height)
		: base(x, y, width, height)
		{
			this.video = (Video)video;
		}

		public ViewPort(VideoI video, Vector2 location, Vector2 size)
		: base(location, size)
		{
			this.video = (Video)video;
		}
		#endregion

		#region Methods
		public override void Apply(RenderTargetI renderTarget)
		{
			if (renderTarget == null)
			{
				var viewPort = new Microsoft.Xna.Framework.Graphics.Viewport()
				{
					X = Location.X,
					Y = video.Device.PresentationParameters.BackBufferHeight - Size.Y - Location.Y,
					Width = Size.X,
					Height = Size.Y,
					MinDepth = 0,
					MaxDepth = 1
				};
				video.Device.Viewport = viewPort;
			}
			else
			{
				var viewPort = new Microsoft.Xna.Framework.Graphics.Viewport()
				{
					X = Location.X,
					Y = renderTarget.Size.Y - Size.Y - Location.Y,
					Width = Size.X,
					Height = Size.Y,
					MinDepth = 0,
					MaxDepth = 1
				};
				video.Device.Viewport = viewPort;
			}
		}
		#endregion
	}
}